﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public static class DirectEvent
    {
        public static void ThrowAsync(Action @event)
        {
            Task.Run(() =>
            {
                var tmp = @event;
                if (tmp != null)
                    tmp();
            });
        }

        public static void ThrowAsync<T>(Action<T> @event, T arg)
        {                
            var tmp = @event;
            if (tmp != null)
                  Task.Run(() =>
                    {
                        tmp(arg);
                    });
        }

        public static void ThrowAsync<T1, T2>(Action<T1, T2> @event, T1 arg1, T2 arg2)
        {
            Task.Run(() =>
            {
                var tmp = @event;
                if (tmp != null)
                    tmp(arg1, arg2);
            });
        }

        public static void ThrowAsync<T1, T2, T3>(Action<T1, T2, T3> @event, T1 arg1, T2 arg2, T3 arg3)
        {
            Task.Run(() =>
            {
                var tmp = @event;
                if (tmp != null)
                    tmp(arg1, arg2, arg3);
            });
        }

        public static void ThrowAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4> @event, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            Task.Run(() =>
            {
                var tmp = @event;
                if (tmp != null)
                    tmp(arg1, arg2, arg3, arg4);
            });
        }

        public static void ThrowAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> @event, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
        {
            Task.Run(() =>
            {
                var tmp = @event;
                if (tmp != null)
                    tmp(arg1, arg2, arg3, arg4, arg5);
            });
        }
    }
}
